﻿using Iworld.Author.Model;
using Iworld.basis.Service;
using Iworld.Basis.Manager;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace Iworld.Author.Service.Client.Import
{
    /// <summary>
    /// 编辑银行信息数据集
    /// </summary>
    [DataContract]
    public class AddOrEditBankImport : CheckAuthorImportBase ,IPackageForUpdateModel<IModelToDbContextOfAuthor,Iworld.Author.Model.Author>
    {
        /// <summary>
        /// 编辑的银行ID
        /// </summary>
        [DataMember]
        public int? BankId { set; get; }

        /// <summary>
        /// 账号
        /// </summary>
        [DataMember]
        public string Account { get; set; }

        /// <summary>
        /// 银行
        /// </summary>
        [DataMember]
        public string Bank { set; get; }

        /// <summary>
        /// 开户人
        /// </summary>
        [DataMember]
        public string Person { set; get; }

        /// <summary>
        /// 备注
        /// </summary>
        [DataMember]
        public string Remark { set; get; }

        public int Id
        {
            get {return this.UserId; }
        }

        public void CheckData(IModelToDbContextOfAuthor db)
        {
          
        }

        public void Update(Model.Author model)
        {
            if(BankId == null)
            {
                AuthorBank newBank = new AuthorBank()
                { 
                    Account = this.Account,
                    Bank = this.Bank,
                    Person = this.Person,
                    Remark = this.Remark
                };
                model.Banks.Add(newBank);
                return;
            }
            AuthorBank bank = model.Banks.Find(x => x.Id == this.BankId);
            bank.Account = this.Account;
            bank.Bank = this.Bank;
            bank.Person = this.Person;
            bank.Remark = this.Remark;
        }
    }
}
